﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using Chi.Lib.DBHelper;

public partial class ShowScript : System.Web.UI.Page
{
    SqlConnection myConnection = DBHelperConnection.GetConnection();//new SqlConnection(ConfigurationManager.ConnectionStrings["MasterDB"].ConnectionString);
    string strSql;
    string spName;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["selected"] == null)
                Response.Write("<script>window.close();</script>");
            spName = Request.QueryString["selected"];
            ServerConnection conn = new ServerConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["MasterDB"].ConnectionString;
            Server server = new Server(conn);

            Database db = server.Databases["Northwind"];

            StoredProcedureCollection spc = db.StoredProcedures;
            if (spName != null)
            {
                StoredProcedure sp = db.StoredProcedures[spName];
                //Response.Write(sp.TextBody);
                this.Label1.Text = "StoredProcedure: " + sp.Name;
                this.TextBox1.Text = sp.TextHeader;
                this.TextBox1.Text += sp.TextBody;
            }
        }
    }

    public void StoredProcedure()
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("<script>window.close();</script>");
    }
}
